<template lang="html">
  <div class="" >
      <div class="add">
          <el-form :model="pageData" ref="ruleForm" label-width="160px" class="demo-ruleForm" v-loading="loading">
                <el-form-item label="收货人姓名">
                  <el-input v-model="pageData.receiveName" placeholder="请输入内容"></el-input>
               </el-form-item>
               <el-form-item label="收货人联系方式">
                 <el-input v-model="pageData.receiveTel" placeholder="请输入内容"></el-input>
              </el-form-item>
              <el-form-item label="收货人地址">
                <el-input v-model="pageData.receiveAddress" placeholder="请输入内容"></el-input>
             </el-form-item>
             <el-form-item id="confirm">
                <el-button type="primary" v-if="btnState == '1'" @click="addOption('post')">提交</el-button>
                <el-button type="primary" v-if="btnState == '2'" @click="addOption('post')">更新</el-button>
             </el-form-item>
          </el-form>
      </div>
  </div>
</template>

<script>
import Data from './takeInfoData.js'
import dialogVue from '@/components/dialog.vue'
import tableVue from '@/components/alltable.vue'
import {
  delTakeInfo,
  addTakeInfo,
  takeInfoList
} from "@/api/product/product";
export default {
  components : {
    tableVue,
    dialogVue
  },
  data () {
    return JSON.parse(JSON.stringify(Data))
  },
  mounted () {
      if (this.pageData = {}) {
          this.btnState = '1';
      } else {
          this.btnState = '2';
      }
      this.getTakeInfoList();
  },
  methods : {
    getTakeInfoList () {
        takeInfoList(JSON.parse(this.$route.query.item)).then(res=>{
          if (res.data.code == 'OK') {
            this.loading = false
              if (res.data.data !== null) {
                 this.pageData = res.data.data;
              }
          } else {
            this.$message.error('获取列表失败');
          }
        })
    },
    addOption (method) {
      var data = {
        receiveName : this.pageData.receiveName,
        receiveTel : this.pageData.receiveTel,
        receiveAddress : this.pageData.	receiveAddress,
        productId : JSON.parse(this.$route.query.item),
      }
      addTakeInfo(data,method).then(res=>{
        if (res.data.code == 'OK') {
          this.dialog = false;
          if (method == 'post') {
            this.$message.success('新增成功');
          } else {
            this.$message.success('编辑成功');
          }
        } else {
          this.$message.error(res.data.message);
        }
      })
    },
  }
}
</script>

<style scoped>
#confirm {
  /* position: absolute;
    left: 380px;
    right: 0; */
}
</style>
